#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 1e5 + 7;
using pii = pair<int, int>;
int d[N], v[N], a[N], p[N], l[N], r[N], dl[N], h[N], n, m, L, V;
vector<int> lk[N];
int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) {
        memset(dl, 0, sizeof dl);
        scanf("%d%d%d%d", &n, &m, &L, &V);
        {
            int i = 0;
            for (int x = 1, td, tv, ta; x <= n; ++x) {
                scanf("%d%d%d", &td, &tv, &ta);
                if (ta == 0 && tv <= V) continue;
                ++i;
                d[i] = td, v[i] = tv, a[i] = ta;
                if (a[i] == 0) {
                    h[i] = L + 1;
                    continue;
                }
                double t = 1.0 * (V - v[i]) / a[i];
                h[i] = ceil(v[i] * t + 0.5 * a[i] * t * t) + d[i];
            }
            n = i;
        }
        for (int i = 1; i <= m; ++i) {
            scanf("%d", p + i);
        }
        for (int i = 1; i <= m; ++i) lk[i].clear();
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i] > 0) {
                l[i] = lower_bound(p + 1, p + 1 + m, h[i]) - p;
                r[i] = m + 1;
            } else {
                l[i] = lower_bound(p + 1, p + 1 + m, d[i]) - p;
                r[i] = lower_bound(p + 1, p + 1 + m, h[i]) - p;
            }
            if (l[i] != r[i]) ++ans;
            for (int j = l[i]; j < r[i]; ++j) {
                lk[j].push_back(i);
            }
        }
        printf("%d ", ans);
        priority_queue<pii, vector<pii>, greater<pii>> pque;
        for (int i = 1; i <= m; ++i) pque.emplace((int)lk[i].size(), i);
        ans = 0;
        while (m--) {
            int i = pque.top().second;
            pque.pop();
            bool flag = true;
            for (int j : lk[i]) {
                if (r[j] - l[j] - dl[j] == 1) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ++ans;
                for (int j : lk[i]) {
                    ++dl[j];
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
/*
1
10 10 150307 247
62978 968 -5
51700 883 -3
40408 564 -1
60366 870 -41
35943 797 -7
47476 595 -11
59020 672 -10
81024 964 -11
80637 695 -5
66114 874 -1
46720 48066 57373 60882 68842 72773 82820 116695 122159 150307
*/
/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 -2
6 4 -4
2 5 8 9 15
*/